package com.server.questionbank.snframe.mapper;

import com.server.questionbank.snframe.domain.TCollection;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface TCollectionMapper {
    // 查询收藏记录
    @Select("SELECT * FROM T_collection WHERE user_id = #{userId} AND target_id = #{targetId} AND target_type = #{targetType}")
    public TCollection selectCollectionByUserAndTarget(@Param("userId") Long userId, @Param("targetId") Long targetId, @Param("targetType") String targetType);
    // 查询收藏记录
    @Select("SELECT * FROM T_collection WHERE user_id = #{userId} AND target_type = #{targetType}")
    public List<TCollection> selectCollectionsByUserAndType(@Param("userId") Long userId, @Param("targetType") String targetType);
    // 查询收藏记录
    @Select("SELECT * FROM T_collection WHERE user_id = #{userId}")
    public List<TCollection> selectCollectionsByUser(@Param("userId") Long userId);
    // 查询收藏记录
    @Select("SELECT * FROM T_collection WHERE collection_id = #{collectionId}")
    public TCollection selectCollectionById(@Param("collectionId") Long collectionId);

    // 添加收藏
    @Insert("INSERT INTO T_collection (user_id, target_id, target_type) VALUES (#{userId}, #{targetId}, #{targetType})")
    public Integer insertCollection(@Param("userId") Long userId, @Param("targetId") Long targetId, @Param("targetType") String targetType);
    // 删除收藏
    @Delete("DELETE FROM T_collection WHERE collection_id = #{collectionId}")
    public Integer deleteCollection(@Param("collectionId") Long collectionId);
}
